package cn.zyy.hotel.interceptor;

import cn.zyy.hotel.utils.SystemConstant;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断session是否为空
        if (request.getSession().getAttribute(SystemConstant.LOGINUSER) == null) {
            //没有登录，跳转登录页面
            response.sendRedirect(request.getContextPath()+"/admin/login.html");
            return false;//没登录，进行拦截
        }
        //登录，通过
        return true;
    }
}
